<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
<script src='/socket.io.js'></script>
<script src='/jquery.js'></script>
<script src='/notify.js'></script>
</head>
<body>

<div class="notification sticky hide">
    <p id="content"> </p>
    <a class="close" href="javascript:"> <img src="/icon-close.png" /></a>
</div>

<a href="javascript:;" class="bt">切换账号</a>
<a href="javascript:;" class="bt_out">退出登录</a>

<center id="online_box"></center>

<script>
$(document).ready(function () {
    //var uid = Date.parse(new Date());
    var uid = 8;
    connect(uid);

    var socket = io('http://'+document.domain+':2120');

    function connect(uid) {
        // var socket = io('http://test.keji110.com:2120');

        // 连接后登录
        socket.on('connect', function(){
            console.log(uid);
            socket.emit('login', uid);
        });

        // 后端推送来消息时
        socket.on('new_msg', function(msg){
            $('#content').html('收到消息：'+msg);
            $('.notification.sticky').notify();
        });
        // 后端推送来在线数据时
        socket.on('update_online_count', function(online_stat){
            $('#online_box').html(online_stat);
        });
    }

    $('.bt').click(function () {
        connect(9,socket)
    })

    $('.bt_out').click(function () {
        socket.emit('disconnect',socket);
    })
});
</script>
</div>
</body>
</html>
